package cn.gdcp.sqlitetest;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

public class MyDatabaseHelper extends SQLiteOpenHelper {
       private Context context;
       private final  String  CREATE_DATABASE="create table Book("
               +"id integer  primary key autoincrement, "
               +"name text, "
               +"height real)";
       private final  String  CREATE_WORKER="create table Worker("
               +"id integer primary key autoincrement, "
               +"name text, "
               +"height real)";
       public  MyDatabaseHelper(Context context, String name,SQLiteDatabase.CursorFactory factory,int version){
           super(context,name,factory,version);
           this.context=context;
       }

    public void onCreate(SQLiteDatabase db) {
           db.execSQL(CREATE_DATABASE);
           db.execSQL(CREATE_WORKER);
        Toast.makeText(context,"创建数据库成功",Toast.LENGTH_SHORT).show();
    }

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
         db.execSQL("drop table if exists Book");
        db.execSQL("drop table if exists Worker");
          onCreate(db);
          Toast.makeText(context,"更新数据库成功",Toast.LENGTH_SHORT);
    }
}
